package com.janson.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.janson.entity.UserInfo;
import com.janson.service.impl.UserInfoServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;

import javax.jws.WebParam;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author janson
 * @since 2022-03-29
 */
@Controller
public class UserInfoController {

    private static boolean flag = false;
    @Autowired
    private UserInfoServiceImpl userInfoService;
    @GetMapping("/userinfo/setting/{uid}")
    public String updateUserInfo(@PathVariable String uid, Model model){
        UserInfo userInfo = userInfoService.getOne(new QueryWrapper<UserInfo>().eq("uid", uid));
        model.addAttribute("userInfo",userInfo);
        if (flag){
            model.addAttribute("updateMsg","用户信息修改成功");
            flag = false;
        }
        return "user/settings";
    }

    @PostMapping("/userinfo/update/{uid}")
    public String updateUserInfo(@PathVariable String uid, UserInfo userInfo, Model model){
        boolean update = userInfoService.updateById(userInfo);
        if (update){
            flag = true;
        }
        return "redirect:/userinfo/setting/"+ uid;
    }
}

